<template>
  <div class="main-container">
    <MyHeader title="商品列表页"></MyHeader>
    <MyTable :list="list">
      <template #head>
        <th>编号</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>
      <template #body="scop">
        <td>{{ scop.row.id }}</td>
        <td>{{ scop.row.goods_name }}</td>
        <td>{{ scop.row.goods_price }}</td>
        <td>
          <button class="btn btn-primary">+Tag</button>
          <input v-focus type="text">
          <span
            style="margin-left: 5px"
            class="badge bg-warning text-dark"
            v-for="(item, index) in scop.row.tags"
            :key="index"
            >{{ item }}</span
          >
        </td>
        <td>
          <button @click="delFn(scop.row.id)" class="btn btn-danger btn-sm">
            删除
          </button>
        </td>
      </template>
    </MyTable>
  </div>
</template>

<script>
import MyHeader from "../components/MyHeader.vue";
import MyTable from "../components/MyTable.vue";
export default {
  name: "Mygoodslist",
  components: {
    MyHeader,
    MyTable,
  },
  data() {
    return {
      list: [],
    };
  },
  async created() {
    let res = await this.$http({ url: "/api/goods" });
    this.list = res.data.data;
  },

  mounted() {},
  directives: {
    focus: {
      inserted(el) {
        el.focus();
      },
    },
  },
  methods: {
    delFn(i) {
      this.list = this.list.filter((ele) => ele.id !== i);
    },
  },
};
</script>

<style lang="less" scoped>
.main-container {
  padding-top: 45px;
}
</style>